<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 导入mapbox依赖 -->
    <script src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
    <script src="https://lib.baomitu.com/axios/latest/axios.js"></script>
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.12.0/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.12.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <!-- 2、设置地图容器的挂载点 -->
    <div id="map">

    </div>
    <script>
        /* 3、实例化地图 */
        mapboxgl.accessToken = 'pk.eyJ1IjoiY2hlbmdiZW5jaGFvIiwiYSI6ImNsODU3aGRiODA0Y2UzcHBzZmFlcmdqZ2sifQ.8k59W_pB_Riwe6o-MneRlA'
        const map = new mapboxgl.Map({
            container: "map",
            /* style-layers */
            style: "mapbox://styles/mapbox/streets-v12",
            center: [114.30, 30.50]
        })
        /* $.ajax */
        let url = 'https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json'
        async function showResult() {
            let data = await $.ajax({ url });
            // let result = await axios.get(url);
            console.log(data)
            /* new ol.format.GeoJSON().readFeatures() */
            /* mapbox --geojson */
            /* 
            id
            source
            type  必选
             */
            map.addLayer({
                id: "china",
                source: {
                    type: "geojson",
                    /* data设置数据地址 */
                    data
                },
                type: "fill",
                paint: {
                    'fill-color': "#ff2d51",
                    'fill-opacity': 0.5
                }
            })
            console.log(map.getStyle().layers)

        }
        map.on("style.load", () => {
            showResult();
            // console.log(map.getStyle().layers)
        })
        /*
        mapbox  addLayer
        source
        type+paint = style
        id
        openlayers addLayer
        source
        style
         */
    </script>
</body>

</html>